<?php
include_once( "common.php" );
checkLogin( STATUS_USER );

# Delete the comment
if ( isValidEntry( "Log", $_GET["id"] ) and isValidEntry( "Bug", $_GET["bug"] ) )
{
    # Make sure the user has permission to delete this comment
    $result = db_query( "SELECT Log.* FROM Log WHERE Log.id = {$_GET["id"]} AND Log.user = {$_SESSION["user"]}" );

    if ( db_num_rows( $result ) == 1 or hasStatus( STATUS_ADMIN ) )
    {
        # See if the comment has no changes associated with it
        $row = db_fetch_object( $result );
        if ( $row->project == "-1" and $row->assigned == "-1" and $row->priority == "-1" and $row->status == "-1" )
            db_query( "DELETE FROM Log WHERE Log.id = {$_GET["id"]}" ) or outputAlert( "Database error", "A database error occurred and the comment was not deleted." );
        else
            db_query( "UPDATE Log SET comment = '' WHERE Log.id = {$_GET["id"]}" ) or outputAlert( "Database error", "A database error occurred and the comment was not deleted." );
        header( "Location: viewBug.php?id={$_GET["bug"]}" );
    }
    else
        outputAlert( "Insufficient privileges", "You do not have sufficient privileges to perform this action." );
}
else
    outputAlert( "Invalid input", "You provided invalid input." );
?>
